home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 21
/
Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso
/
Aminet
/
util
/
rexx
/
cliped16.lha
/
cliped
/
cliped.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1997-08-15
|
10KB
|
343 lines
/*
** $VER: cliped.rexx 1.5 (17.5.97) Rolf Rotvel
**
** Uses rexxreqtools.library
*/
call addlib('rexxreqtools.library', 0, -30, 0)
call addlib('rexxsupport.library', 0, -30, 0)
nl = '0a'x
cr = '0d'x
sep = '¤'
title = subword(sourceline(2), 3, 2)
call get_clips()
do forever
ans = rtezrequest(mainbody, maingads, title)
select
when ans = 0 then exit
when ans = 1 then do
if numclips = 0 then call create_clip()
else do
if numclips > 1 then num = rxlistview(300, 200, 'Select clip to edit')
else num = 1
if num ~= 0 then call view_clip(num)
end
end
when ans = 2 then call create_clip()
otherwise exit 10
end
end
GET_CLIPS:
clipnames = show('c',, sep)
if clipnames ~= '' then do
c = 1
len = 0
do forever
parse var clipnames clip.name.c (sep) clipnames
if clip.name.c = '' then leave /* No more clips */
clip.value.c = checklf(getclip(clip.name.c)) /* Check clips for lf/cr */
len = max(len, length(clip.name.c))
c = c + 1
end
numclips = c - 1
do f = 1 to numclips
viewline.f = left(clip.name.f, len)||' : '||clip.value.f
end
if numclips = 1 then ext = 'entry'
else ext = 'entries'
maingads = '_Edit clip list|_Create new clip|_Quit'
mainbody = numclips||' '||ext||' '||'in clip list'
end
else do
numclips = 0
maingads = 'Create _new clip|_Quit'
mainbody = 'Clip list is empty'
end
viewline.0 = numclips
return
VIEW_CLIP:
arg clipnum
body = 'Name : '||clip.name.clipnum||nl||'Value : '||clip.value.clipnum
gads = '_Edit clip|_Delete clip|_Cancel'
ans = rtezrequest(body, gads, title)
select
when ans = 0 then return
when ans = 1 then call edit_clip(clipnum)
when ans = 2 then call delete_clip(clipnum)
otherwise exit 10
end
return
EDIT_CLIP:
arg clipnum
body = 'Enter new value for '||clip.name.clipnum
ans = rtgetstring(clip.value.clipnum, body, title)
if rtresult = 0 | ans = '' then return
if confirm('Use this value?', clip.name.clipnum, ans) then do
call setclip(clip.name.clipnum, addlf(ans)) /* Convert \nl \cr -> nl cr */
call get_clips()
end
return
DELETE_CLIP:
arg clipnum
if confirm('Delete this clip?', clip.name.clipnum, clip.value.clipnum) then do
call setclip(clip.name.clipnum, '')
call get_clips()
end
return
CREATE_CLIP:
newname = rtgetstring(, 'Enter the name of the new clip', title)
if rtresult = 0 | newname = '' then return
chkvalue = getclip(newname)
if chkvalue ~= '' then do
do clipcount = 1 to numclips
if clip.name.clipcount = newname then leave
end
if confirm('Clip already exists! Change value?', clip.name.clipcount, clip.value.clipcount) then do
call edit_clip(clipcount)
end
return
end
newvalue = rtgetstring(, 'Enter the value of the new clip', title)
if rtresult = 0 | newvalue = '' then return
if confirm('Create this clip?', newname, newvalue) then do
call setclip(newname, addlf(newvalue))
call get_clips()
end
return
CONFIRM: procedure expose title nl
parse arg txt, name, value
body = txt||nl||'Name : '||name||nl||'Value : '||value
gads = '_Ok|_Cancel'
if rtezrequest(body, gads, title) then return 1
return 0
RXLISTVIEW: procedure expose viewline. rxlv.
parse arg argwidth, argheight, titletxt
/* Initialize when listview is opened for the first time */
if rxlv.init? ~= 1 then call init_rxlistview(argwidth, argheight)
/* Create formatted stem variable for listview */
do v = 1 to viewline.0
displine.v = left(viewline.v, rxlv.dispcols)
end
displine.0 = viewline.0
/* Which is bigger - win rows or lines in stemvar? */
if rxlv.disprows > displine.0 then rxlv.disprows = displine.0
/* Get current mouse coordinates */
intui = showlist(l, 'intuition.library',, a)
call forbid
screen = next(intui, 56) /* IntuitionBase->ActiveScreen */
mousex = c2d(import(offset(screen, 18), 2)) - 50 /* Screen->MouseX */
mousey = c2d(import(offset(screen, 16), 2)) - 50 /* Screen->MouseY */
call permit
/* Open the listview */
call open('listwin', 'RAW:'||mousex||'/'||mousey||'/'||rxlv.width||'/'||rxlv.height||'/'||titletxt||'/NOSIZE', 'w')
call writech('listwin', rxlv.nocursor||rxlv.nowordwrap)
/* Do ze stuff */
row = 1 ; var = row
call writech('listwin', getlighty(row, var)||rxlv.nl||getpage(var + 1))
res = '' ; topvar = 1
do forever
oldrow = row ; oldvar = var
char = readch('listwin', 1)
select
when char = rxlv.csi then do
char = readch('listwin', 1)
select
when char = rxlv.cursordown & oldvar ~= displine.0 then do
line = getunlighty(oldrow, oldvar)
var = var + 1
if oldrow < rxlv.disprows then row = row + 1
else do
line = line||rxlv.nl
row = rxlv.disprows
topvar = topvar + 1
end
call writech('listwin', line||getlighty(row, var))
end
when char = rxlv.cursorup & oldvar ~= 1 then do
line = getunlighty(oldrow, oldvar)
var = var - 1
if oldrow ~= 1 then do
row = row - 1
call writech('listwin', line||getlighty(row, var))
end
else do
row = 1
topvar = topvar - 1
call writech('listwin', line||getlighty(row, var)||rxlv.nl||getpage(var + 1))
end
end
when char = rxlv.scursorup & oldvar ~= 1 then do
row = 1
if oldrow = 1 then do
if oldvar - rxlv.disprows < 1 then topvar = 1
else topvar = oldvar - rxlv.disprows
var = topvar
call writech('listwin', rxlv.cls||getlighty(row, var)||rxlv.nl||getpage(topvar + 1))
end
else do
var = topvar
call writech('listwin', getunlighty(oldrow, oldvar)||getlighty(row, var))
end
end
when char = rxlv.scursordown & oldvar ~= displine.0 then do
row = rxlv.disprows
if oldrow = rxlv.disprows then do
if oldvar + rxlv.disprows > displine.0 then topvar = displine.0 - (rxlv.disprows - 1)
else topvar = oldvar + 1
var = min(displine.0, topvar + (rxlv.disprows - 1))
call writech('listwin', rxlv.cls||getpage(topvar)||rxlv.nl||getlighty(row, var))
end
else do
var = (topvar + rxlv.disprows) - 1
call writech('listwin', getunlighty(oldrow, oldvar)||getlighty(row, var))
end
end
otherwise nop
end
end
when char = rxlv.esc then do
call close('listwin')
return 0
end
when char = rxlv.cr then do
call close('listwin')
return oldvar
end
otherwise nop
end
end
GETPAGE: procedure expose displine. rxlv.
parse arg topvar
if displine.0 = 1 then return ''
page = ''
do y = 1 to rxlv.disprows - 2 /* Lines between first and last */
page = page||displine.topvar||rxlv.nl
topvar = topvar + 1
end
page = page||displine.topvar /* No newline after last line */
return page
GETUNLIGHTY: procedure expose rxlv. displine.
parse arg row, var .
return rxlv.csi||row||';1H'||displine.var
GETLIGHTY: procedure expose rxlv. displine.
parse arg row, var .
return rxlv.csi||row||';1H'||rxlv.hilite||displine.var||rxlv.off
INIT_RXLISTVIEW: procedure expose rxlv.
/* Hardcoded minimum values */
rxlv.width = max(100, arg(1))
rxlv.height = max(50, arg(2))
/* ANSI stuff */
rxlv.csi = '9b'x ; rxlv.esc = '1b'x
rxlv.nl = '0a'x ; rxlv.cr = '0d'x
rxlv.off = rxlv.csi||'0m'
rxlv.topleft = rxlv.csi||'48'x
rxlv.cls = rxlv.csi||'H'||rxlv.csi'J'
rxlv.hilite = rxlv.csi||'43;32m'
rxlv.nowordwrap = rxlv.csi||'3f376c'x
rxlv.nocursor = rxlv.csi||'302070'x
rxlv.cursorup = '41'x ; rxlv.cursordown = '42'x
rxlv.scursorup = '54'x ; rxlv.scursordown = '53'x
/* GUI constants */
guiheight = 7 ; guiwidth = 8
/* Font info */
intui = showlist(l, 'intuition.library',, a)
call forbid
screen = next(intui, 56) /* IntuitionBase->ActiveScreen */
font = next(screen, 136) /* Screen->RastPort.Font */
fonty = c2d(import(offset(font, 20), 2)) /* Font->YSize */
fontx = c2d(import(offset(font, 24), 2)) /* Font->XSize */
call permit
/* Listview width */
do while (rxlv.width - guiwidth) // fontx ~= 0
rxlv.width = rxlv.width + 1
end
rxlv.dispcols = ((rxlv.width - guiwidth) % fontx)
/* Listview height */
const = guiheight + fonty
do while (rxlv.height - const) // fonty ~= 0
rxlv.height = rxlv.height + 1
end
rxlv.disprows = (rxlv.height - const) % fonty
/* We only need to do all this once */
rxlv.init? = 1
return
REPLACE: procedure
parse arg src, new, old
str = ''
do while src ~= ''
chk = pos(old, src)
parse var src pre (old) src
str = str||pre
if chk > 0 then str = str||new
end
return str
CHECKLF: procedure expose nl cr
str = arg(1)
if pos(nl, str) > 0 then str = replace(str, '\n', nl)
if pos(cr, str) > 0 then str = replace(str, '\r', cr)
return str
ADDLF: procedure expose nl cr
str = arg(1)
if pos('\n', str) > 0 then str = replace(str, nl, '\n')
if pos('\r', str) > 0 then str = replace(str, cr, '\r')
return str